<template>
  <el-form :model="form" @submit.prevent="handleLogin">
    <el-input v-model="form.username" placeholder="用户名" />
    <el-input v-model="form.password" type="password" placeholder="密码" />
    <el-button type="primary" native-type="submit">登录</el-button>
  </el-form>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const form = ref({ username: '', password: '' })
const router = useRouter()

const handleLogin = async () => {
  const response = await axios.post('http://localhost:8000/api/auth/login/', form.value)
  localStorage.setItem('token', response.data.token)
  router.push('/dashboard')
}
</script>
